package com.jt.www.admin.pay.controller;

import com.jt.www.admin.pay.service.PayCertService;
import com.jt.www.model.issue.RepushQo;
import com.jt.www.model.pay.StatusRecordVO;
import com.jt.www.model.pay.vo.PayCertVO;
import com.jt.www.model.remote.ins.InsResultVO;
import com.jt.www.model.reps.ResultDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author admin_ltf
 * @create 2019-06-03 14:23
 */
@Api(value = "上传延期支付证明绑定和修改状态", tags = {"PAY-UPDATE-API"}, description = "上传延期支付证明绑定和修改状态")
@RestController
@RequestMapping(value = "/pay/cert")
public class PayCertController {

    public static final Logger log = LoggerFactory.getLogger(PayCertController.class);

    @Autowired
    PayCertService payCertService;

    @ApiOperation(value = "绑定和修改状态", notes = "绑定和修改状态", httpMethod = "POST")
    @PostMapping(value = "/bindAndUpdateData")
    public ResultDTO<List<InsResultVO>> bindAndUpdateData(@RequestBody PayCertVO vo) {


        ResultDTO resultDTO = null;
        try {
            resultDTO = payCertService.bindAndUpdateData(vo);
        } catch (Exception e) {
            e.printStackTrace();
        }


        return resultDTO;
    }

    @ApiOperation(value = "修改状态", notes = "修改状态", httpMethod = "POST")
    @PostMapping(value = "/updateStatus")
    public ResultDTO<List<InsResultVO>> updateApplicationStatus(@RequestBody List<StatusRecordVO> statusRecordVOs) {

        ResultDTO resultDTO = payCertService.updateApplicationStatus(statusRecordVOs);

        return resultDTO;
    }

    /**
     * 失败报文重发
     *
     * @param repushQo 针对没有主承的报文
     * @return
     */
    @ApiOperation(value = "报文重发", notes = "报文重发", httpMethod = "POST")
    @PostMapping(value = "/issueRepush")
    public ResultDTO<List<InsResultVO>> retransmissionMessage(@RequestBody RepushQo repushQo) {

        ResultDTO resultDTO = payCertService.updateMessageStatus(repushQo);

        return resultDTO;
    }

    /**
     * 失败报文重发
     * 针对有多个跟单的报文
     *
     * @param repushQo
     * @return
     */
    @ApiOperation(value = "跟单失败报文重发", notes = "跟单失败报文重发", httpMethod = "POST")
    @PostMapping(value = "/backIssueRepush")
    public ResultDTO<List<InsResultVO>> backIssueRepush(@RequestBody RepushQo repushQo) {

        ResultDTO resultDTO = payCertService.updateBackMessageStatus(repushQo);

        return resultDTO;
    }

    /**
     * 重新获取电子保单
     *
     * @param repushQo
     * @return
     */
    @ApiOperation(value = "获取电子保单", notes = "获取电子保单", httpMethod = "POST")
    @PostMapping(value = "/getPolicy")
    public ResultDTO getPolicy(@RequestBody RepushQo repushQo) throws Exception {
        ResultDTO resultDTO = payCertService.getPolicy(repushQo);
        return resultDTO;
    }

    /**
     * 重新获取电子发票
     *
     * @param repushQo
     * @return
     */
    @ApiOperation(value = "获取电子发票", notes = "获取电子发票", httpMethod = "POST")
    @PostMapping(value = "/getInvoice")
    public ResultDTO getInvoice(@RequestBody RepushQo repushQo) throws Exception {
        ResultDTO resultDTO = payCertService.getInvoice(repushQo);
        return resultDTO;
    }

    /*
     *  发票红冲
     * @Author xq.wu
     * @Date 15:59 2020/1/8
     * @Param [repushQo]
     * @return com.jt.www.model.reps.ResultDTO
     **/
    @ApiOperation(value = "发票红冲", notes = "发票红冲", httpMethod = "POST")
    @PostMapping(value = "/redRushInvoice")
    public ResultDTO redRushInvoice(@RequestBody RepushQo repushQo, String mark) throws Exception {
        ResultDTO resultDTO = payCertService.redRushInvoice(repushQo, mark);
        return resultDTO;
    }

}
